package cn.edu.sjtu.stap.hg;

import java.util.*;

import org.aspectj.org.eclipse.jdt.internal.compiler.ast.*;

import cn.edu.sjtu.stap.graph.*;

public class TypeNode extends GraphNode {
    private static final long serialVersionUID = 1L;

    private static long nodeCount = 0;

    private TypeNodeKind kind = null;

    private TypeDeclaration declaration = null;

    private Set<AbstractMethodDeclaration> intertypeMethods = new HashSet<AbstractMethodDeclaration>();

    public TypeNode(TypeNodeKind kind) {
        super(++nodeCount);
        this.kind = kind;
    }

    public TypeNodeKind getKind() {
        return kind;
    }

    public void setTypeDeclaration(TypeDeclaration d) {
        declaration = d;
    }

    public TypeDeclaration getTypeDeclaration() {
        return declaration;
    }

    public void addIntertypeMethod(AbstractMethodDeclaration m) {
        intertypeMethods.add(m);
    }

    public Set<AbstractMethodDeclaration> getMethodDeclarations() {
        Set<AbstractMethodDeclaration> s = new HashSet<AbstractMethodDeclaration>();

        if (declaration.methods != null) {
            for (int i = 0; i < declaration.methods.length; ++i) {
                s.add(declaration.methods[i]);
            }
        }
        s.addAll(intertypeMethods);

        return s;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();

        sb.append("(Node ");
        sb.append(getId());
        sb.append(": ");
        sb.append(getTypeDeclaration().binding.readableName());
        sb.append(")");

        return sb.toString();
    }
}
